package com.htd.erp.common;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Conversation;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@ApplicationScoped
public class LifeCycleUtils {
	
	@Inject
	private Instance<Conversation> conversation;
	
	public void startConversation() {
		if (getConversation().isTransient()) {
			getConversation().begin();
		}
	}
	
	public void endConversation() {
		if (!getConversation().isTransient()) {
			getConversation().end();
		}
	}
	
	public Conversation getConversation() {
		return conversation.get();
	}
}
